home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / SeeMovieRun 1.0 / sources / CMovie.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  7.7 KB  |  339 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CMovie.c
  3.  
  4.                             The Movie Class
  5.         
  6.         Displays a standard QuickTime Movie.
  7.         
  8.         This is a read-only class that allows you to specify and play a QuickTime
  9.         movie with minimal other features. It is designed to simply allow the
  10.         importation and display of movie files. The movies are controlled by
  11.         the standard movie controller.
  12.         
  13.         This class could be expanded to allow editing and more…
  14.     
  15.     SUPERCLASS = CPane
  16.     
  17.     Copyright © 1992 Joe Zobkiw. All rights reserved.
  18.     Portions Copyright © 1990 Symantec Corporation.  All rights reserved.
  19.  
  20.  ******************************************************************************/
  21.  
  22. #include "CMovie.h"
  23. #include "CCollaborator.h"
  24. #include "CEBCollaborator.h"
  25. #include "Defines.h"
  26. #include <Commands.h>
  27. #include <Global.h>
  28. #include <CPaneBorder.h>
  29. #include <TCLUtilities.h>
  30. #include <TBUtilities.h>
  31.  
  32. extern  CEBCollaborator    *gEBCollaborator;
  33.  
  34. /******************************************************************************
  35.  IMovie
  36.  
  37.         Initialize a Movie object
  38.  ******************************************************************************/
  39.  
  40. void    CMovie::IMovie(
  41.     CView            *anEnclosure,
  42.     CBureaucrat        *aSupervisor,
  43.     short            aWidth,
  44.     short            aHeight,
  45.     short            aHEncl,
  46.     short            aVEncl,
  47.     SizingOption    aHSizing,
  48.     SizingOption    aVSizing,
  49.     FSSpec             *movieSpec)
  50. {
  51.     
  52.     CPane::IPane(anEnclosure, aSupervisor,
  53.                     aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
  54.     
  55.     //
  56.     // we want to receive clicks
  57.     //
  58.     
  59.     SetWantsClicks(true);
  60.     
  61.     //
  62.     // we want a simple border in case we decide to resize the frame to be
  63.     // smaller than it’s enclosure. this will make it look nicer.
  64.     //
  65.     
  66.     itsBorder = new(CPaneBorder);
  67.     itsBorder->IPaneBorder(kBorderFrame);
  68.  
  69.     //
  70.     // initialize our instance variables
  71.     //
  72.     
  73.     movie = NULL;
  74.     movieRefNum = 0;
  75.     controller = NULL;
  76.  
  77.     //
  78.     // we want be a gopher!
  79.     //
  80.     
  81.     SetCanBeGopher(true);
  82.     BecomeGopher(true);
  83.  
  84.     //
  85.     // we want to recieve events from gEBCollaborator which is our provider…
  86.     // the one whom we depend upon
  87.     //
  88.     
  89.     DependUpon(gEBCollaborator);
  90.  
  91.     //
  92.     // if we have a movie to open (the user selected Open… instead of New) then
  93.     // open the movie!
  94.     //
  95.     
  96.     if (movieSpec != NULL)
  97.         ImportMovie(movieSpec);
  98. }
  99.  
  100. /******************************************************************************
  101.  Dispose  (OVERRIDE)
  102.  
  103.         Dispose of a Movie object
  104.  ******************************************************************************/
  105.  
  106. void    CMovie::Dispose()
  107. {
  108.     ForgetInstanceVariables();
  109.     CancelDependency(gEBCollaborator);
  110.     inherited::Dispose();
  111. }
  112.  
  113. /******************************************************************************
  114.  ProviderChanged
  115.  
  116.     Our Provider has changed
  117. ******************************************************************************/
  118.  
  119. void CMovie::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
  120. {
  121.     switch(reason) {
  122.     
  123.         //
  124.         // kEventRecordReason is the only reason we deal with these days
  125.         //
  126.         
  127.         case kEventRecordReason: {
  128.         
  129.             short             eventHandled;
  130.             
  131.             //
  132.             // we might end up drawing because of this MCPlayer event
  133.             // so we must be sure our port is set up correctly.
  134.             //
  135.             
  136.             Prepare();
  137.             
  138.             //
  139.             // see if the movie controller would like the event or not
  140.             //
  141.             
  142.             eventHandled = MCIsPlayerEvent(controller, (EventRecord*)info);
  143.             if (eventHandled == true) {
  144.                 
  145.                 //
  146.                 // we handled the event so we change it to a null event
  147.                 // so it is (in effect) ignored elsewhere.
  148.                 //
  149.                 
  150.                 ((EventRecord*)info)->what = nullEvent;                
  151.             }
  152.                         
  153.             }
  154.             break;
  155.             
  156.         default:
  157.             break;
  158.     }
  159.     
  160.     inherited::ProviderChanged(aProvider, reason, info);
  161. }
  162.  
  163. /******************************************************************************
  164.  DoClick  (OVERRIDE)
  165.  
  166.         This will get called if we click outside of the movie but still
  167.         within the Movie Pane (which is currently sticky to the size of the window)
  168.  ******************************************************************************/
  169.  
  170. void    CMovie::DoClick(Point hitPt, short modifierKeys, long when)
  171. {
  172.     //
  173.     // this alert will beep the first two times and show itself the third time
  174.     // and thereafter. It will simply remind the user that clicking in the empty
  175.     // area of the CMovie Pane is fruitless other than showing this annoying alert.
  176.     //
  177.     
  178.     if (active)
  179.         NoteAlert(kMovieDoClickALRT, nil);
  180. }
  181.  
  182. /******************************************************************************
  183.  ImportMovie
  184.  
  185.         Use the movie pointed to by spec as our movie. This routine imports 
  186.         the given movie, replacing any previous movies that were used in this pane.
  187.         
  188.  ******************************************************************************/
  189. void    CMovie::ImportMovie(FSSpec *spec)
  190. {
  191.     Rect            movieRect;
  192.     Boolean            locked;
  193.         
  194.     //
  195.     // hop out if there is no spec to import
  196.     //
  197.     
  198.     if (spec == NULL) return;
  199.  
  200.     //
  201.     // lock ourselves down and prepare for drawing, etc.
  202.     //
  203.     
  204.     locked = Lock(true);
  205.     Prepare();
  206.     
  207.     //
  208.     // forget our current movie & controller, if we have them
  209.     //
  210.     
  211.     ForgetInstanceVariables();
  212.     
  213.     //
  214.     // open the movie file and create a new movie from the file
  215.     //
  216.     
  217.     FailOSErr(OpenMovieFile(spec, &movieRefNum, fsRdPerm));
  218.     FailOSErr(NewMovieFromFile(&movie, movieRefNum, nil, nil, newMovieActive, nil));
  219.     
  220.     //
  221.     // get the bounds for the movie and make sure the top left is 0,0
  222.     // so the movie won't be offset within the window
  223.     //
  224.     
  225.     GetMovieBox(movie, &movieRect);            
  226.     FailOSErr(GetMoviesError());
  227.     OffsetRect(&movieRect,-movieRect.left,-movieRect.top);
  228.     SetMovieBox(movie, &movieRect);            
  229.     FailOSErr(GetMoviesError());
  230.  
  231.     //
  232.     // rewind the movie
  233.     //
  234.     
  235.     GoToBeginningOfMovie(movie);            
  236.     FailOSErr(GetMoviesError());
  237.  
  238.     //
  239.     // create our controller
  240.     //
  241.     
  242.     controller = NewMovieController(movie, &movieRect, mcWithFrame+mcTopLeftMovie);
  243.     FailOSErr(GetMoviesError());
  244.     
  245.     //
  246.     // redraw ourselves
  247.     //
  248.     
  249.     Refresh();
  250.  
  251.     //
  252.     // reset our locked state
  253.     //
  254.     
  255.     Lock(locked);
  256. }
  257.  
  258.  
  259. /******************************************************************************
  260.  Dawdle {OVERRIDE}
  261.  
  262.         Call MoviesTask here if we have a movie and it is playing. MoviesTask()
  263.         handles updating the movie for us. It will update the movie in the background
  264.         also.
  265.         
  266.  ******************************************************************************/
  267.  
  268. void    CMovie::Dawdle(long    *maxSleep)
  269. {
  270.     if (movie != NULL) {
  271.         if (!IsMovieDone(movie)) {
  272.             Prepare();                        // get ready to draw
  273.             MoviesTask(movie, 0);            // update the movie
  274.             FailOSErr(GetMoviesError());    // check the error condition
  275.         }
  276.     }
  277. }
  278.  
  279.  
  280. /******************************************************************************
  281.  Draw {OVERRIDE}
  282.  
  283.         Draw a Movie and the controller if need be.
  284.         
  285.  ******************************************************************************/
  286.  
  287. void    CMovie::Draw(Rect *area)
  288. {
  289.     Rect            tempRect;
  290.     
  291.     //
  292.     // prepare to draw
  293.     //
  294.     
  295.     Prepare();
  296.     
  297.     //
  298.     // draw our movie or fill the pane with gray pattern if we have no movie
  299.     //
  300.  
  301.     if (movie == NULL) {
  302.         LongToQDRect( &aperture, &tempRect);
  303.         FillRect(&tempRect, &gray);
  304.     } else {
  305.         UpdateMovie(movie);                // update the movie next time MoviesTask is called        
  306.         FailOSErr(GetMoviesError());    // check for errors
  307.         MoviesTask(movie, 0);            // actually perform the update
  308.         FailOSErr(GetMoviesError());    // check for errors
  309.     }
  310.     
  311.     //
  312.     // if we have a controller, draw it here
  313.     //
  314.     
  315.     if (controller != NULL) {
  316.         MCDraw(controller, GetMacPort());
  317.     }
  318. }
  319.  
  320. /******************************************************************************
  321.  ForgetInstanceVariables
  322.  
  323.         clears the instance variables of this class
  324.  ******************************************************************************/
  325. void CMovie::ForgetInstanceVariables(void)
  326. {
  327.     if (movie != NULL) {
  328.         DisposeMovie(movie);
  329.         movie = NULL;
  330.     }
  331.     if (movieRefNum != 0) {
  332.         CloseMovieFile(movieRefNum);
  333.         movieRefNum = 0;
  334.     }
  335.     if (controller != NULL) {
  336.         DisposeMovieController(controller);
  337.         controller = NULL;
  338.     }
  339. }